package pattern;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;
import pattern.cache.MsgCache;
import pattern.feign.FileFeign;
import pattern.utils.SpringTool;

import java.lang.reflect.InvocationTargetException;

/**
 * 提供spring bean 服务调用
 * @author Simon
 * @date 2020-09-01 18:41
 **/
@Data
@Slf4j
public class SmsServiceTool {


    public static <T> T getService(Class<T> service) {
        return SpringTool.getBean(service);
    }

    public static Object invoke(Class<?> service, String realMethod, Class[] c, @Nullable Object... args) throws InvocationTargetException, IllegalAccessException {
        var method = SpringTool.findMethod(service, realMethod, c);
        return method.invoke(getService(service),args);
    }


    public static MsgCache getMsgCache() {
        return getService(MsgCache.class);
    }

    public static FileFeign getFileFeign() {
        return getService(FileFeign.class);
    }


}
